

object practice {

  def main(args: Array[String]): Unit = {

    //7.1
    var filename = "readme.txt"

    if (!args.isEmpty) filename = args(0)

    println(filename)

    val fileName = if (!args.isEmpty) args(0) else "readme.txt"


    //7.2
    def greet() = {
      println("hi")
    }

    println(() == greet())

    //7.3
    for (i <- 1 to 4) {
      println("Iteration " + i)
    }
    for (i <- 1 until 4) {
      println("Iteration " + i)
    }

    //for的过滤器
    val filesHere = (new java.io.File(".")).listFiles()
    for (file <- filesHere if file.getName.contains("2"))
      println(file)

    for (file <- filesHere)
      if (file.getName.contains("2"))
        println(file)

    val fileWith2 = for {file <- filesHere if file.getName.contains("2")} yield file
    println(fileWith2.toList)

    //7.4
//    val n = 9
//    val half = if (n % 2 == 0)
//      n / 2
//    else
//      throw new RuntimeException("n must be even")
//
//    println(half)

    //7.6

    var i = 0
    var foundIt = false
    for (file <- filesHere if file.getName.contains("2") && !foundIt){
      if(file.getName.contains("28")){
        foundIt = true
      }
      println(file)
      i = i+1
    }

    println("i===>"+i)

  }

}
